package mini.hug;

import java.awt.Point;

import owg.util.Calc;
import owg.util.opengl.ColorF;
import hubol.Entity;

public class Heart extends Entity{
	public final static double DISTANCE = 48;
	
	private Shake s = Hug.me.shake();
	
	private final int id;
	private double distX, distY, ddistX, ddistY;
	private double drawX, drawY, in;
	
	private boolean kill = false;

	public Heart(double x, double y, int id) {
		super(x, y);
		this.id = id;
		setDepth(600 - (int)y);
		drawX = x;
		drawY = y;
		in = 0;
	}
	
	public void kill(){
		kill = true;
	}
	
	public void step(){
		Point p = Hug.me.getBogus();
		double a = x, b = y;
		if (p.distance(x, y) >= DISTANCE * id){
			x = Calc.approach(x, p.x, 8 + id);
			y = Calc.approach(y, p.y, 8 + id);
			if (p.distance(x, y) < DISTANCE * id){
				x = a;
				y = b;
			}
		}
		
		drawX = Calc.approach(drawX, x, 8);
		drawY = Calc.approach(drawY, y, 8);
		
		setDepth(600 - (int)y);
		
		if (!kill)
			in = Calc.approach(in, 1, 6);
		else{
			in -= .018 + ((3 - id) * .008);
			if (in <= 0)
				destroy();
		}
	}
	
	public void rememberDistance(){
		Point p = Hug.me.getBogus();
		distX = x - p.x;
		distY = y - p.y;
		ddistX = drawX - p.x;
		ddistY = drawY - p.y;
	}
	
	public void forceUpdate(){
		Point p = Hug.me.getBogus();
		x = p.x + distX;
		y = p.y + distY;
		drawX = p.x + ddistX;
		drawY = p.y + ddistY;
	}
	
	public void render(){
		Hug.HEART.render(0, drawX + s.x, drawY + s.y - (22 * in), (float)(.35 * in), (float)(.35 * in), (float)(s.z / 5.0), ColorF.WHITE);
	}

}
